package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.comment.domain.ScenicSpotComment;
import cn.wolfcode.luowowo.comment.query.ScenicSpotCommentQuery;
import cn.wolfcode.luowowo.comment.service.IScenicSpotCommentService;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.website.web.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/scenicSpotComment")
public class ScenicSpotCommentController {
    @Reference
    private IScenicSpotCommentService scenicSpotCommentService;

    @RequestMapping("/commentAdd")
    public Object commentAdd(Model model,ScenicSpotComment comment, @UserParam UserInfo user) {

       /* if (user == null) {
            AjaxResult result = new AjaxResult(false, "请先进行登录");
            result.setCode(102);
            return result;
        }*/

        //设置作者信息
        comment.setUserId(user.getId());
        comment.setLevel(user.getLevel());
        comment.setHeadUrl(user.getHeadImgUrl());
        comment.setUsername(user.getNickname());

        ScenicSpotComment scenicSpotComment = scenicSpotCommentService.saveOrUpdate(comment);
        model.addAttribute("c",scenicSpotComment);
        return "destination/scenicCommentAddTpl";
    }

    @RequestMapping("/commentList")
    public String list(Model model, @ModelAttribute("qo")ScenicSpotCommentQuery qo) {
        //一级评论
        Page page=scenicSpotCommentService.query(qo);
        model.addAttribute("page", page);


        //二级评论
        qo.setPageSize(Integer.MAX_VALUE);
        Page pageAll=scenicSpotCommentService.queryAll(qo);
        model.addAttribute("pageAll", pageAll);
        return "destination/scenicCommentTpl";
    }



}
